//
//  ToggleSprite.m
//  SpaceStorm
//
//  Created by 祥 雍 on 13-6-17.
//  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
//
//
//  组合sprite,有激活和非激活2个状态，对应2张不同的图片

#import "ToggleSprite.h"

@implementation ToggleSprite


+(id) spriteWithActive:(NSString*)activeFrameName unactive:(NSString*)unActiveframeName
{
    return [[[self alloc] initWithActive:activeFrameName unactive:unActiveframeName] autorelease]; 
}

-(id) initWithActive:(NSString*)activeFrameName unactive:(NSString*)unActiveframeName
{
    if( (self=[super init])) 
    {
        //创建2个状态的图片
        _activeSprite = [CCSprite spriteWithSpriteFrameName:activeFrameName]; 
        _activeSprite.anchorPoint = ccp(0, 0);
        [self addChild:_activeSprite];
        _unactiveSprite = [CCSprite spriteWithSpriteFrameName:unActiveframeName]; 
        _unactiveSprite.anchorPoint = ccp(0, 0);
        [self addChild:_unactiveSprite];
        
        //设置 contendSize
        self.contentSize = _activeSprite.contentSize;
        
        //默认状态下是非激活的
        [self setActive:NO];
    }
    
    return self;
}

/**
	设置组合图片的状态
	@param isActive 激活状态只显示激活的图片，非激活状态只显示非激活的图片
 */
-(void) setActive:(BOOL)isActive

{
    if(isActive)
    {
        _activeSprite.visible = YES;
        _unactiveSprite.visible = NO;
    }
    else
    {
        _activeSprite.visible = NO;
        _unactiveSprite.visible = YES;
    }
}

- (void) dealloc
{
	// don't forget to call "super dealloc"
	[super dealloc];
}

@end
